frontend/pages/e/[uuid]/adminWaitingList.tsx (view raw)
1import {PropsWithChildren} from 'react';
2import EventLayout, {TabComponent} from '../../../layouts/Event';
3import pageUtils from '../../../lib/pageUtils';
4import {EventByUuidDocument} from '../../../generated/graphql';
5import TripAlertsList from '../../../containers/TripAlertsList';
6
7interface Props {
8 eventUUID: string;
9 announcement?: string;
10}
11
12const Page = (props: PropsWithChildren<Props>) => {
13 return <EventLayout {...props} Tab={WaitingListTab} tabProps={props} />;
14};
15
16const WaitingListTab: TabComponent<Props> = ({event}) => {
17 return <TripAlertsList />;
18};
19
20export const getServerSideProps = pageUtils.getServerSideProps(
21 async (context, apolloClient, session) => {
22 const {uuid} = context.query;
23 const {host = ''} = context.req.headers;
24 let event = null;
25
26 // Fetch event
27 try {
28 const {data} = await apolloClient.query({
29 query: EventByUuidDocument,
30 variables: {uuid},
31 });
32 event = data?.eventByUUID?.data;
33 } catch (error) {
34 return {
35 notFound: true,
36 };
37 }
38
39 const isCarosterPlus =
40 event?.attributes?.enabled_modules?.includes('caroster-plus');
41 if (!isCarosterPlus)
42 return {
43 notFound: true,
44 };
45
46 const userEmail = session?.user?.email;
47 const userIsAdmin =
48 event?.attributes?.adminstrators?.includes(userEmail) ||
49 event?.attributes?.email === userEmail;
50 if (!userIsAdmin) return {notFound: true};
51
52 return {
53 props: {
54 eventUUID: uuid,
55 metas: {
56 title: event?.attributes?.name || '',
57 url: `https://${host}${context.resolvedUrl}`,
58 },
59 },
60 };
61 }
62);
63
64export default Page;